﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;

namespace GenerationCode
{
    public partial class frmInputKey : Form
    {
        public IList lstKey;
        public bool isSetPrimaryKey = false;
        public frmInputKey()
        {
            InitializeComponent();
        }
        public frmInputKey(IList lst)
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();
            lstBoxFields.Items.Clear();
            lstBoxPrimaryKeys.Items.Clear();
            foreach (Utils.Column col in lst)
            {
                this.lstBoxFields.Items.Add(col.Name);
            }
            this.lstKey = new ArrayList();
            //
            // TODO: Add any constructor code after InitializeComponent call
            //
        }

        private void btnOk_Click(object sender, System.EventArgs e)
        {
            if (lstKey.Count < 0)
            {
                MessageBox.Show(this, "Please choose primary key(s).", "Error!");
                return;
            }
            this.lstKey = this.lstBoxPrimaryKeys.Items;
            if(radSetPrimaryKey.Checked)
                this.isSetPrimaryKey=true;
            else
                this.isSetPrimaryKey=false;            
            this.Close();
        }

        private void btnAdd_Click(object sender, System.EventArgs e)
        {
            int count = this.lstBoxFields.SelectedItems.Count;
            for (int i = 0; i < count; i++)
            {
                this.lstBoxPrimaryKeys.Items.Add(this.lstBoxFields.SelectedItems[0]);
                this.lstBoxFields.Items.Remove(this.lstBoxFields.SelectedItems[0]);
            }
        }
        private void btnRemove_Click(object sender, System.EventArgs e)
        {
            int count = this.lstBoxPrimaryKeys.SelectedItems.Count;
            for (int i = 0; i < count; i++)
            {
                this.lstBoxFields.Items.Add(this.lstBoxPrimaryKeys.SelectedItems[0]);
                this.lstBoxPrimaryKeys.Items.Remove(this.lstBoxPrimaryKeys.SelectedItems[0]);
            }
        }
        private void btnCancel_Click(object sender, System.EventArgs e)
        {
            this.Close();
        }


        private void lstBoxPrimaryKeys_DoubleClick(object sender, EventArgs e)
        {
            this.btnRemove_Click(sender, e);
        }

        private void lstBoxFields_DoubleClick(object sender, EventArgs e)
        {
            this.btnAdd_Click(sender, e);
        }
    }
}
